﻿Imports DMC.Database.clsDatabase
Imports DMC.Database
Public Class Clslaphosophaply
    Private strConnection As String = ""
    Private strMaDonViHanhChinh As String = ""
    Private strNgay As String = ""
    Private strMaHoLap As String = ""
    Dim Paras() As String = {"@GiaTriMaVach", "@Ngay", "@MaHoSo", "@action"}
    Private straction As String = ""
    Private strError As String = ""


    Public ReadOnly Property Err() As String
        Get
            Return strError
        End Get
    End Property
    Public Property Action() As String
        Get
            Return straction
        End Get
        Set(ByVal value As String)
            straction = value
        End Set
    End Property
    Public Property MaHoSo() As String
        Get
            Return strMaHoLap
        End Get
        Set(ByVal value As String)
            strMaHoLap = value
        End Set
    End Property

    Public Property Connection() As String
        Get
            Return strConnection
        End Get
        Set(ByVal value As String)
            strConnection = value
        End Set
    End Property
    Public Property MaDonViHanhChinh() As String
        Get
            Return strMaDonViHanhChinh
        End Get
        Set(ByVal value As String)
            strMaDonViHanhChinh = value
        End Set
    End Property
    Public Property Ngay() As String
        Get
            Return strNgay
        End Get
        Set(ByVal value As String)
            strNgay = value
        End Set
    End Property
 
    Public Function GetData_SP(ByVal sp As String, ByVal paras() As String, ByVal Values() As String) As DataTable
        Dim strError As String = ""
        Dim MyTable As New DataTable
        Try
            'Khoi tao doi tuong DMC.clsDatabase
            Dim Database As New clsDatabase
            Database.Connection = strConnection
            If (Database.OpenConnection) Then
                'Chắc chắn rằng mảng giá trị truyền vào tương đương với mảng tham biến
                If (paras.Length <> Values.Length) Then
                    Return Nothing
                End If
                'Gọi phương thức GetValue của đối tượng clsDatabase
                Database.getValue(MyTable, sp, paras, Values)
                Database.CloseConnection()
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return MyTable
    End Function

    Private Function Execute(ByVal strStoreProcedure As String, ByRef records As Integer) As String
        Try
            'Khoi tao doi tuong clsSqlDatabase
            Dim Database As New clsDatabase
            'Neu ket noi co so du lieu thanh cong
            Database.Connection = strConnection
            If Database.OpenConnection = True Then
                'Khai bao mang gia tri
                Dim Values() As String = _
                {"", "", strMaHoLap, straction}
                'Chắc chắn rằng mảng giá trị truyền vào tương đương với mảng tham biến
                If (Paras.Length <> Values.Length) Then
                    Return "Mảng giá trị chuyền vào chưa phù hợp!"
                End If
                'Goi phuong thuc ExecuteSP cua doi tuong clsSQLDatabase
                Database.ExecuteSP(strStoreProcedure, Paras, Values, records)
                Database.CloseConnection()
                strError = ""
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return strError
    End Function
    Public Function Delete(ByRef intRecords As Integer) As String
        Return Me.Execute("SelectQuetTimThongTinByMaVach", intRecords)
    End Function
    Public Function SelectDVHC() As DataTable
        Dim dt As New DataTable
        Dim strError As String = ""
        Dim ParaDVHC() As String = {"@MaDVHC"}
        Try
            Dim Values() As String = {strMaDonViHanhChinh}
            dt = GetData_SP("spSelectHuyenTinh", ParaDVHC, Values)
            strError = ""
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return dt
    End Function

End Class
